<?php

namespace SinoPHP\BbdBoss\Api;

use InvalidArgumentException;
use Upfor\UpforPHP\Library\Math;

/**
 * 获取策略接口
 *
 * 用于API系统获取策略列表
 *
 */
class GetPolicyList extends ApiAbstract {

    public function v_1_0_0() {
        $field = 'policy_id as id,policy_name as name,server_weight as user_qos_weight,cost_weight,is_minimum as guarantee_weight,ip_num as min_ip,mini_usability as qos_minValue,same_isp,same_province,other_isp,other_province';
        $policyList = model('Policy')->getList($field);
        if (!$policyList) {
            throw new InvalidArgumentException('', 107002);
        }
        foreach ($policyList as &$value) {
            $value['id'] = (int)$value['id'];
            $value['user_qos_weight'] = (int)$value['user_qos_weight'];
            $value['cost_weight'] = (int)$value['cost_weight'];
            $value['guarantee_weight'] = $value['guarantee_weight'] ? True : False;
            $value['min_ip'] = (int)$value['min_ip'];
            $value['qos_minValue'] = (int)$value['qos_minValue'];
            $value['same_isp'] = (int)$value['same_isp'];
            $value['same_province'] = (int)$value['same_province'];
            $value['other_isp'] = (int)$value['other_isp'];
            $value['other_province'] = (int)$value['other_province'];
        }

        $this->success($policyList);
    }

}
